<?php
namespace app\index\controller;

use app\BaseController;
use think\facade\Db;

class Tmp extends BaseController
{
  public function info(){

    $token = request()->param('token');

    $activity = Db::table('activity')->where('token', $token)->find();
    if (!$activity){
      returnJson(-3, '没有该活动！');
    }

    $start_time = strtotime($activity['start_time']);
    $end_time = strtotime($activity['end_time']);
    $nowTime = strtotime(date("Y-m-d"),time());
    
    if ($start_time > $nowTime) {
      returnJson(-3, '活动未开始！');
    }
    if ($end_time < $nowTime) {
      returnJson(-3, '活动已结束！');
    }
 
    $banner = Db::table('activity_banner')->where('a_id', $activity['id'])->select();

    $ids = explode(',', $activity['goods_ids']);
    $goods = Db::table('shop_goods')->order('sort', 'asc')->whereIn('id', $ids)->select();

    $data = [
      'activity' => $activity,
      'banner' => $banner,
      'goods' => $goods,
    ];
    
    returnJson(0, '成功！', $data);
  }

}
